package cn.tj.wenda.cloud.bas.entity;

import java.util.Date;

/**
 * 校验登录次数时使用
 * @author Wenda
 * @date 2018年4月12日
 */
public class LoginHis {
	private int _loginNum = 0;
	private boolean locked = false;
	private long lockedTime = 0;
	private int timeLenth = 0;//超时
	
	public long getCurrCecond() {
		return (new Date()).getTime() / 1000;
	}

	public int getLoginNum() {
		return _loginNum;
	}

	public void setLoginNum(int _loginNum) {
		this._loginNum = _loginNum;
	}

	public boolean isLocked() {
		return locked;
	}

	public void setLocked(boolean locked) {
		this.locked = locked;
		if(locked)
			this.lockedTime = this.getCurrCecond();
		else
			this.lockedTime = 0;
	}

	public long getLockedTime() {
		return lockedTime;
	}

	public int getTimeLenth() {
		return timeLenth;
	}

	public void setTimeLenth(int timeLenth) {
		this.timeLenth = timeLenth;
	}

	/**
	 * 判断账号锁定时间，如果还在锁定中，返回剩余时间（分钟），否则返回<=0的值
	 * @return
	 */
	public int checkLocked() {
		if(this.isLocked()) {//已锁定
			long loginTime = this.getCurrCecond() - this.getLockedTime();
			if(loginTime <= this.timeLenth) {
				double dblLast = (double) ((this.timeLenth-loginTime)/60);
				int last;
				if(dblLast >= 0 && dblLast < 1)
					last = 1;
				else
					last = (int)dblLast;
				
				return last;
			}
			else {//解除锁定
				this._loginNum = 0;
				this.locked = false;
				this.lockedTime = 0;
				
				return 0;
			}
		}
		return 0;
	}
}
